import {
  get
} from '../../utils/http'

Page({
  data: {
    latitude: '',
    longitude: '',
    markers: []
  },
  onReady() {
    this.mapContext = wx.createMapContext('map')
    wx.getLocation({
      type: 'wgs84',
      success: (res) => {
        this.setData({
          longitude: res.longitude,
          latitude: res.latitude
        })
      }
    });
    this.getMarkers();
  },

  moveToCenter() {
    console.log(0)
    this.mapContext.moveToLocation()
  },
  goPublish() {
    wx.navigateTo({
      url: '/pages/publish/publish',
    })
  },
  async getMarkers() {
    ///index.php/trade/get_list
    let rs = await get('/index.php/trade/get_list')
    console.log(rs)
    let arr = [];
    rs.data.forEach((item) => {
      arr.push({
        longitude: item.longitude,
        latitude: item.latitude,
        iconPath: item.type === 'buy' ? '/images/buy.png' : '/images/sell.png'
      })
    })
    this.setData({
      markers:arr
    })

  }


})